---
name: Selecting fields
---

# Selecting fields

Genql queries are similar to graphql queries in structure, to select some fields you pass an object where the keys are the field names.

Here is an example of a query made with the client generated from the Quick start guide

```js
import { createClient } from './generated'

const client = createClient()

client
    .query({
        countries: {
            name: true,
            code: true,
            languages: {
                name: true,
            },
        },
    })
    .then(console.log)
```

# Passing arguments

If you want to pass arguments to a query you must use an array where the first object represents the arguments and the second object the fields selection.

```js
import { createClient } from './generated'
const client = createClient()

client
    .query({
        countries: [
            {
                filter: { code: 'BR' },
            },
            {
                name: true,
                code: true,
                languages: {
                    name: true,
                },
            },
        ],
    })
    .then(console.log)

client
    .mutation({
        createUser: [{ user: { name: 'user' } }, { name: true, age: true }],
    })
    .then(console.log)
```

# Querying all fields

Genql let you query all scalar fields in a type by using the `everything` object:

```js
import { everything } from './generated' // everything is just an object: const everything = { __scalar: true };

client
    .query({
        countries: {
            ...everything, // same as __scalar: true
            languages: {
                ...everything,
            },
        },
    })
    .then((x) => console.log(JSON.stringify(x)))
```

> `everything` queries only the leaf types, you have to manually query object types

## Excluding fields

You can also exclude some fields from the selection passing falsy values

```js
client
    .query({
        countries: {
            ...everything, // same as __scalar: true
            id: false,
            code: false,
        },
    })
    .then((x) => console.log(JSON.stringify(x)))
```

# Using the chain syntax

Genql has an alternative way of executing queries called `chain` mode.

The chain mode let you access fields using dot notation instead of an object:

```js
import { createClient } from './generated'

const client = createClient()

const name = await client.chain.mutation.createUser({ name: 'john' }).name.get()
```
